package com.tavio.vaultboy.game;

import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;

import com.tavio.vaultboy.element.Box;
import com.tavio.vaultboy.element.Button;
import com.tavio.vaultboy.element.VaultBoy;
import com.tavio.vaultboy.scene.SceneManager;

public class GameUpdaterCallBack implements ITimerCallback {

	private long currTime;
	
	private float timeElapsed;
	
	private long lastTime;
	
	private VaultBoy vaultBoy;
	
	public GameUpdaterCallBack(VaultBoy vaultBoy) {
		this.vaultBoy = vaultBoy;
		currTime = lastTime = System.currentTimeMillis();
	}

	public void onTimePassed(TimerHandler pTimerHandler) {
		currTime = System.currentTimeMillis();
		timeElapsed = (float)(currTime - lastTime) / 1000;
		lastTime = currTime;
	
		vaultBoy.updatePositionAndCheckCollisions(timeElapsed);
		for(Box box : SceneManager.getInstance().boxes) {
			box.updatePositionAndCheckCollisions(timeElapsed);
		}
		for(Button button : SceneManager.getInstance().buttons) {
			button.updatePositionAndCheckCollisions(timeElapsed);
		}
		if(SceneManager.getInstance().bullet != null) {
			SceneManager.getInstance().bullet.updatePositionAndCheckCollisions(timeElapsed);
		}
		
	}

}
